package nicg.st.dao;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import nicg.st.entity.EvalMethodPO;
import nicg.st.entity.EvalParamPO;
import nicg.st.entity.ExpertScorePO;
import nicg.st.entity.IndicatorBase2PO;
import nicg.st.entity.IndicatorBasePO;
import nicg.st.entity.IndicatorDetailPO;
import nicg.st.entity.InputParamInfo;
import nicg.st.entity.JSFFPO;
import nicg.st.entity.ParamCalPO;
import nicg.st.entity.ParamPrototype;
import nicg.st.entity.PresetParamInfo;

@Mapper
public interface IndicatorSystemMapper {

	List<IndicatorBasePO> getAllIndicatorBasePO(String userId);

	Integer getIndicatorSystemCount(String userId);

	List<IndicatorBasePO> getIndicatorSystemByPage(@Param("offset") Integer offset, @Param("userId") String userId,
			@Param("limit") Integer limit);

	List<IndicatorDetailPO> getOrderdIndicatorDetailByIndicatorId(Integer indicatorId);

	/**
	 * 返回固定指标体系id的根据指标路径排序的所有指标详情
	 * 
	 * @param indicatorId
	 * @return
	 */
	List<IndicatorDetailPO> getDoubleOrderdIndicatorDetailByIndicatorId(@Param("indicatorId") Integer indicatorId);

	IndicatorDetailPO getRootIndicatorDetailByIndicatorId(Integer indicatorId);

	IndicatorDetailPO getIndicatorDetailByIndicatorName(@Param("indicatorName") String indicatorName,
			@Param("indicatorId") int indicatorId);

	/**
	 * 根据指标体系的id获取指标体系的名称
	 * 
	 * @param indicatorId
	 * @return
	 */
	String getIndicatorBaseNameByIndicatorId(int indicatorId);

	/**
	 * 根据指标体系名称返回指标体系
	 * 
	 * @param indicatorsysName
	 * @return
	 */
	IndicatorBasePO getIndicatorInfoByName(@Param("indicatorsysName") String indicatorsysName);

	/**
	 * 插入新的指标体系表
	 * 
	 * @param taskName
	 * @param userId
	 * @param createTime
	 * @param remark
	 * @param category
	 * @param parentId
	 * @param userLevel
	 * @param taskType
	 * @param indicatorsysName
	 * @return
	 */
	Integer insertIndicatorBasePO(@Param("taskName") String taskName, @Param("userId") String userId,
			@Param("createTime") Date createTime, @Param("remark") String remark, @Param("category") String category,
			@Param("parentId") Integer parentId, @Param("userLevel") Integer userLevel,
			@Param("taskType") Integer taskType, @Param("indicatorsysName") String indicatorsysName);

	/**
	 * 插入数据到指标详情表
	 * 
	 * @param indicatorSystemId
	 * @param indicatorName
	 * @param indicatorPath
	 * @param indicatorLevel
	 * @param relativeWeight
	 * @param absoluteWeight
	 * @param paramId
	 * @param remark
	 * @return
	 */
	Integer insertIndicatorBaseDetail(@Param("indicatorSystemId") Integer indicatorSystemId,
			@Param("indicatorName") String indicatorName, @Param("indicatorPath") String indicatorPath,
			@Param("indicatorLevel") Integer indicatorLevel, @Param("relativeWeight") Double relativeWeight,
			@Param("absoluteWeight") Double absoluteWeight, @Param("paramId") Integer paramId,
			@Param("remark") String remark);

	List<IndicatorDetailPO> getSecondByIndicatorId(int indicatorId);

	List<IndicatorDetailPO> getIndicatorDetailByLevel(@Param("indicatorSystemId") Integer indicatorSystemId,
			@Param("indicatorLevel") Integer indicatorLevel);

	Integer insertExpertScore(@Param("indicatorSystemId") Integer indicatorSystemId,
			@Param("indicatorName") String indicatorName, @Param("indicatorPath") String indicatorPath,
			@Param("relativeWeight") Double relativeWeight, @Param("absoluteWeight") Double absoluteWeight,
			@Param("judgmentMatrix") String judgmentMatrix, @Param("expertName") String expertName);

	List<ExpertScorePO> getExpertScoreListByIndicatorId(@Param("expertName") String expertName,
			@Param("indicatorSystemId") int indicatorSystemId);

	ExpertScorePO getExpertScoreByIndicatorIdAndName(@Param("indicatorSystemId") Integer indicatorSystemId,
			@Param("indicatorName") String indicatorName, @Param("expertName") String expertName);

	Integer updateJudgmentMatrixById(@Param("id") Integer id, @Param("judgmentMatrix") String judgmentMatrix);

	/**
	 * 更新专家打分表中的权重信息
	 * 
	 * @param id
	 * @param relativeWeight
	 * @return
	 */
	Integer updateRelativeWeightByPrimaryId(@Param("id") Integer id, @Param("relativeWeight") Double relativeWeight);

	List<ExpertScorePO> getExpertScoreByExpertNameAndIndicatorId(@Param("expertName") String expertName,
			@Param("indicatorSystemId") Integer indicatorSystemId);

	List<ExpertScorePO> getChildNodeByName(@Param("indicatorSystemId") Integer indicatorSystemId,
			@Param("expertName") String expertName, @Param("indicatorName") String indicatorName);

	/**
	 * 更新指标体系明细表中的权重信息
	 * 
	 * @param id
	 * @param relativeWeight
	 * @return
	 */
	int updateDetailRelativeWeightByES(@Param("id") Integer id, @Param("relativeWeight") Double relativeWeight);

	IndicatorDetailPO getIndicatorDetailByIndicatorSystemIdAndIndicatorName(
			@Param("indicatorSystemId") Integer indicatorSystemId, @Param("indicatorName") String indicatorName);

	List<IndicatorDetailPO> getIndicatorDetailByIndicatorLevelAndIndicatorNameLike(
			@Param("indicatorLevel") int indicatorLevel, @Param("indicatorName") String indicatorName,
			@Param("indicatorSystemId") int indicatorSystemId);

	List<IndicatorDetailPO> getIndicatorDetailByIndicatorSystemIdAndIndicatorLevel(
			@Param("indicatorSystemId") int indicatorSystemId, @Param("indicatorLevel") int indicatorLevel);

	ParamCalPO getParamCalPOByNodeId(int nodeId);

	/**
	 * 将每个结点的计算方法插入到CSJS表中
	 * 
	 * @param nodeId
	 * @param method
	 * @return
	 */
	int insertParamCalPO(@Param("nodeId") int nodeId, @Param("method") int method);

	List<EvalParamPO> getEvalParamPOsByNodeId(Integer nodeId);

	int insertEvalParamPO(@Param("nodeId") int nodeId, @Param("paramName") String paramName,
			@Param("paramValue") Double paramValue);

	/**
	 * 删除节点的计算方法
	 * 
	 * @param nodeId
	 */
	void deleteParamCalItemsByNodeId(int nodeId);

	void deleteParamSetItemsByNodeId(int nodeId);

	/**
	 * 删除指标体系id下的所有指标
	 * 
	 * @param indicatorId
	 */
	void deleteDetailByIndicatorId(int indicatorId);

	/**
	 * 删除指标体系id的指标体系base
	 * 
	 * @param indicatorId
	 */
	void deleteBaseByIndicatorId(int indicatorId);

	/**
	 * 根据主键id查找指标体系明细
	 * 
	 * @param indicatorId
	 * @return
	 */
	IndicatorDetailPO getIndicatorDetailPOById(int indicatorId);

	List<EvalMethodPO> getEvalMethodPOsByMethodId(int methodId);

	int updateEvalMethodPOByMethodId(@Param("nodeId") int nodeId, @Param("methodId") int methodId);

	EvalMethodPO getEvalMethodPOByNodeId(int nodeId);

	int updateEvalParamPOByPrimaryId(@Param("id") int id, @Param("paramName") String paramName,
			@Param("paramValue") double paramValue);

	void deleteIndicatorDetailById(int id);

	// 得到所有的计算方法PO
	List<JSFFPO> getAllJSFFs();

	// 根据methodId更新JSFF中的Doc信息
	void updateJSFFByNodeIdAndDoc(@Param("methodId") int methodId, @Param("methodDoc") String methodDoc);

	// 根据指标内容获取AM
	IndicatorDetailPO getAMByIndicatorSystemIdAndIndicatorLevelAndIndicatorName(
			@Param("indicatorSystemId") Integer indicatorSystemId, @Param("indicatorName") String indicatorName,
			@Param("indicatorLevel") Integer indicatorLevel);

	/**
	 * 插入新的指标体系
	 * 
	 * @param taskName
	 * @param createTime
	 * @param remark
	 * @param category
	 * @param parentId
	 * @param userLevel
	 * @param taskType
	 * @param userId
	 * @param indicatorsysName
	 * @return
	 */
	int insertIndicatorBase2PO(@Param("taskName") String taskName, @Param("createTime") Date createTime,
			@Param("remark") String remark, @Param("category") String category, @Param("parentId") Integer parentId,
			@Param("userLevel") Integer userLevel, @Param("taskType") Integer taskType, @Param("userId") String userId,
			@Param("indicatorsysName") String indicatorsysName);

	IndicatorBase2PO getIndicatorInfoByIndicatorsysName(@Param("indicatorsysName") String indicatorsysName);

	List<IndicatorDetailPO> getIndicatorDetailsByPrimaryKey(@Param("indicatorSystemId") int indicatorSystemId);

	/**
	 * 返回指定方法的参数模板
	 * 
	 * @param methodId
	 * @return
	 */
	List<ParamPrototype> getParamPrototypesByMethodId(@Param("methodId") int methodId);

	/**
	 * 返回某节点的输入参数信息
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @return
	 */
	InputParamInfo getInputParamsByNodeIdAndParamPrototype(@Param("nodeId") Integer nodeId,
			@Param("paramPrototype") String paramPrototype);

	/**
	 * 返回某节点的预设参数信息
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @return
	 */
	PresetParamInfo getPresetParamsByNodeIdAndParamPrototype(@Param("nodeId") int nodeId,
			@Param("paramPrototype") String paramPrototype);

	/**
	 * 删除nodeId有关的输入参数信息
	 * 
	 * @param nodeId
	 */
	void deleteInputParamInfosByNodeId(@Param("nodeId") Integer nodeId);

	/**
	 * 删除nodeId有关的预设参数信息
	 * 
	 * @param nodeId
	 */
	void deletePresetParamInfosByNodeId(@Param("nodeId") Integer nodeId);

	/**
	 * 插入新的输入参数信息
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @param paramName
	 * @param paramValue
	 */
	void insertInputParamInfo(@Param("nodeId") int nodeId, @Param("paramPrototype") String paramPrototype,
			@Param("paramName") String paramName, @Param("paramValue") double paramValue,
			@Param("paramMaxId") Integer paramMaxId, @Param("paramMinId") Integer paramMinId,
			@Param("paramStepId") Integer paramStepId);

	/**
	 * 插入新的预设参数信息
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @param paramName
	 * @param paramValue
	 */
	void insertPresetParamInfo(@Param("nodeId") int nodeId, @Param("paramPrototype") String paramPrototype,
			@Param("paramName") String paramName, @Param("paramValue") double paramValue);

	/**
	 * 返回节点的所有输入参数信息
	 * 
	 * @param nodeId
	 * @return
	 */
	List<InputParamInfo> getInputParamsByNodeId(@Param("nodeId") Integer nodeId);

	/**
	 * 更新改指定指标体系的指标体系名称
	 * 
	 * @param id
	 * @param indicatorsysName
	 */
	void updateBaseNameByIndicatorSystemId(@Param("id") Integer id, @Param("indicatorsysName") String indicatorsysName);

	/**
	 * 更新指定指标的指标名称
	 * 
	 * @param id
	 * @param indicatorName
	 */
	void updateIndicatorNameByPrimaryId(@Param("id") Integer id, @Param("indicatorName") String indicatorName);

	/**
	 * 查询指定指标体系下指标路径中含有指定名称的指标信息
	 * 
	 * @param indicatorSytemId
	 * @param indicatorPath
	 * @return
	 */
	List<IndicatorDetailPO> getIndicatorDetailByIndicatorPathHas(@Param("indicatorSystemId") int indicatorSytemId,
			@Param("indicatorName") String indicatorName);

	/**
	 * 更新指定指标的指标路径
	 * 
	 * @param id
	 * @param indicatorPath
	 */
	void updateIndicatorPathByPrimaryId(@Param("id") Integer id, @Param("indicatorPath") String indicatorPath);

	/**
	 * 更新指定方法的计算说明
	 * 
	 * @param methodId
	 * @param methodDoc
	 */
	void updateCalMethodDocByMethodId(@Param("methodId") int methodId, @Param("methodDoc") String methodDoc);

	/**
	 * 通过指标id和参数原型更新预设参数的信息
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @param paramName
	 * @param paramValue
	 */
	void updatePresetParamsInfo(@Param("nodeId") int nodeId, @Param("paramPrototype") String paramPrototype,
			@Param("paramName") String paramName, @Param("paramValue") Double paramValue);

	/**
	 * 通过指标id和参数原型更新输入参数的参数名称
	 * 
	 * @param nodeId
	 * @param paramPrototype
	 * @param paramName
	 */
	void updateInputParamsInfo(@Param("nodeId") int nodeId, @Param("paramPrototype") String paramPrototype,
			@Param("paramName") String paramName);

	/**
	 * 通过指标id获取所有的预设参数
	 * 
	 * @param nodeId
	 * @return
	 */
	List<PresetParamInfo> getPresetParamsByNodeId(@Param("nodeId") Integer nodeId);

}
